{% extends "base.html" %}
{% block body %}
<div id="payloadCreation" style="margin-top:5px">
    <div class="card">
        <div class="card-header bg-header border border-dark shadow text-white">
            <h3 style="display:inline-block"><span class="operator">Operating System</span> Information</h3>
            <button style="float:right" class="btn btn{{config['outline-buttons']}}info btn-md" @click="import_payload_config()">Import Payload Config</button>
        </div>
        <div class="collapse show" id="os-card-body">
            <div class="card-body border border-dark shadow bg-card-body border-0">
                <select class="form-control" v-model="selected_os" style="width:auto">
                    <option v-for="o in os_options" :value="o">[[o]]</option>
                </select>
            </div>
            <div class="card-footer bg-card-footer border border-dark shadow">
                <button class="btn btn{{config['outline-buttons']}}success" id="move_to_c2_button" @click="move_to_c2()">Next</button>
            </div>
        </div>
    </div>
    <div class="card">
        <div class="card-header bg-header border border-dark shadow text-white">
            <h3><span class="operator">C2 Profile</span> Information</h3>
        </div>
        <div class="collapse" id="c2-card-body">
            <template v-for="(cp, i) in c2_profile_list">
                <div class="card-header bg-header border border-dark shadow text-white">
                    <button class="btn btn-sm btn{{config['outline-buttons']}}danger" @click="remove_c2_profile(cp, i)"><i class="fas fa-trash-alt"></i></button>
                    &nbsp;&nbsp;Select a C2 Profile to add to your payload.<br>
                </div>
                <div class="card-body border border-dark shadow bg-card-body border-0">
                    <select :disabled="!c2_buttons" :style="!c2_buttons ? 'display:inline-block;width:auto;cursor:not-allowed' : 'display:inline-block;width:auto'" class="form-control" id="cp.c2_profile" v-model="cp.selected_c2_profile">
                        <option v-for="c in filtered_c2_options(cp)" :value="c.name">
                            <template v-if="c['payload_types'].length > 0">
                                [[c.name + " - " + c['payload_types'].join(", ") ]]
                            </template>
                            <template v-else>
                                [[c.name]]
                            </template>
                        </option>
                    </select>
                    <select style="display:inline-block;width:auto" class="form-control" :id="'c2_instance' + i" hidden v-model="cp.selected_c2_instance">
                        <option value=" Select One...">Select One...</option>
                        <option v-for="(value, k, s) in cp.c2_instance_values" :value="k">[[k]]</option>
                    </select><br>
                    <div id="cp.c2ParameterFormFields">
                        <template v-if="cp.c2_profile_parameters.length != 0">
                            <table class="table table-condensed table-striped {{config['table-color']}}" id="c2_param_table" style="word-wrap: break-word;width:100%">
                                <tr>
                                    <th style="text-align:left"><b>Parameter Name</b></th>
                                    <th style="text-align:left"><b>Parameter Value</b></th>
                                </tr>
                                <tr v-for="(value, index) in cp.c2_profile_parameters" :key="value.name" >
                                    <td style="width:20rem;padding-left:10px">
                                       [[value.description]]
                                        <template v-if="value.required">
                                            <br><font color="indianred"><b>(Required)</b></font>
                                        </template>
                                    </td>
                                    <td>
                                        <template v-if="value.parameter_type === 'String'">
                                            <template v-if="!passing_requirements(value)">
                                                <font color="indianred"><b>(Bad Value)</b></font>
                                            </template>
                                            <textarea class="form-control" :id="[[value.name]]" oninput="adjust_size(this)" rows="1" :value="value.parameter" v-model="value.parameter" style="white-space: nowrap; width:100%"></textarea>
                                        </template>
                                        <template v-else-if="value.parameter_type === 'ChooseOne'">
                                            <select class="form-control" v-model="value.parameter">
                                                <option v-for="o in value.default_value.split('\n')" :value="o">[[o]]</option>
                                            </select>
                                        </template>
                                        <template v-else-if="value.parameter_type === 'Date'">
                                            <div class='input-group date' data-provide="datepicker" data-date-format="yyyy-mm-dd" data-date-today-highlight="true" data-date-autoclose="true" :id="'newparaminst' + value.id" onchange="profile_parameters_table.update(event)">
                                                <input class="form-control" :value="value.parameter" v-model="value.parameter">
                                                <div class="input-group-append">
                                                    <button class="btn btn-sm btn{{config['outline-buttons']}}secondary"><i class="far fa-calendar-alt fa-2x"></i></button>
                                                </div>
                                            </div>
                                        </template>
                                        <template v-else-if="value.parameter_type === 'Array'">
                                            <template v-if="!passing_requirements(value)">
                                                <font color="indianred"><b>(Bad Value)</b></font>
                                            </template>
                                            <div v-for="(e, i) in value.parameter">
                                                <div class="input-group">
                                                    <button class="btn btn-sm btn{{config['outline-buttons']}}danger" @click="remove_array_element(value, i) "><i class="far fa-trash-alt"></i></button>
                                                    <input type="text" class="form-control" v-model="value.parameter[i]" :value="value.parameter[i]">
                                                </div>
                                            </div>
                                            <button class="btn btn-sm btn{{config['outline-buttons']}}success" @click="add_array_element(value.parameter)"><i class="fa fa-plus"></i></button>
                                        </template>
                                        <template v-else-if="value.parameter_type === 'Dictionary'">
                                            <template v-for="(o, i) in value.parameter">
                                                <div class="input-group">
                                                    <button class="btn btn-sm btn{{config['outline-buttons']}}danger" @click="remove_dict_element(value, i)"><i class="far fa-trash-alt"></i></button>
                                                    <button disabled class="btn btn-sm btn-secondary">Key:</button>
                                                    <template v-if="o['custom']">
                                                        <input type="text" :value="o['key']" class="text form-control" v-model="value.parameter[i]['key']">
                                                    </template>
                                                    <template v-else>
                                                        <input disabled :value="o['name']" class="text form-control">
                                                    </template>
                                                    <button disabled class="btn btn-sm btn-secondary">Value:</button>
                                                    <input type="text" class="form-control" :value="value.parameter[i]['value']" v-model="value.parameter[i]['value']">
                                                </div>
                                            </template>
                                            <template v-if="can_add_more(value)">
                                                <div class="input-group">
                                                    <button class="btn btn-sm btn{{config['outline-buttons']}}success" @click="add_dict_element(value)"><i class="fa fa-plus"></i></button>
                                                    <button disabled class="btn btn-sm btn-secondary">New key of type:</button>
                                                    <select v-model="value['new_key']" class="form-control">
                                                        <option v-for="o in add_options(value)" :value="o">
                                                            <template v-if="o === '*'">
                                                                Custom
                                                            </template>
                                                            <template v-else>
                                                                [[ o ]]
                                                            </template>
                                                        </option>
                                                    </select>

                                                </div>
                                            </template>
                                        </template>
                                    </td>
                                </tr>
                            </table>
                        </template>
                    </div>
                </div>
            </template>
            <div :hidden="!c2_buttons" class="card-footer bg-card-footer border border-dark shadow">
                <button class="btn btn{{config['outline-buttons']}}warning" id="move_c2_payloads_button" @click="move_from_c2()">Back</button>
                <button class="btn btn{{config['outline-buttons']}}info" id="add_c2_profile_button" @click="add_c2_profile()">Include Additional C2</button>
                <button class="btn btn{{config['outline-buttons']}}success" id="move_to_payloads_button" @click="move_to_payloads()">Next</button>
            </div>
        </div>
    </div>
    <div class="card">
        <div class="card-header bg-header border border-dark shadow text-white">
            <h3><span class="operator">Payload Type</span> Information</h3>
        </div>
        <div class="collapse" id="payload-card-body">
            <div class="card-body border shadow border-dark bg-card-body">
                <template v-if="payload_type_options.length > 1">
                    Select a payload type that supports the C2 Profile you just selected.<br>
                    <select class="form-control" id="payload_type" v-model="selected_payload_type" :disabled="!pt_buttons" :style="!pt_buttons ? 'display:inline-block;width:auto;cursor:not-allowed' : 'display:inline-block;width:auto'">
                        <option v-for="p in payload_type_options" :value="p">[[p]]</option>
                    </select><br>
                    <div id="payloadParameterFormFields">
                        <template v-if="payload_parameters.length != 0">
                            <table class="table table-condensed table-striped {{config['table-color']}}" id="payloadParameterTable" style="word-wrap: break-word;width:100%">
                                <tr>
                                    <th style="text-align:left;width:25rem"><b>Parameter Name</b></th>
                                    <th style="text-align:left"><b>Parameter Value</b></th>
                                </tr>
                                <tr v-for="(value, index) in payload_parameters" :key="value.name" v-if="value.parameter_type !== 'None'">
                                    <td style="width:25rem;padding-left:10px">
                                        <template v-if="value.description !== ''">
                                            [[value.description]]
                                        </template>
                                        <template v-else>
                                            [[value.name]]
                                        </template>
                                        <template v-if="value.required">
                                            <br><font color="indianred"><b>(Required)</b></font>
                                        </template>
                                    </td>
                                    <td>
                                        <template v-if="!passing_payload_requirements(value)">
                                            <font color="indianred"><b>(Bad Value)</b></font>
                                        </template>
                                        <template v-if="value.parameter_type === 'String'">
                                            <textarea class="form-control" type="text" style="width:100%" :placeholder="[[value.parameter]]" v-model="value.value"></textarea>
                                        </template>
                                        <template v-else-if="value.parameter_type === 'ChooseOne'">
                                            <select class="form-control" v-model="value.value"><option v-for="opt in value.choices" v-model="opt">[[opt]]</option></select>
                                        </template>
                                        <template v-else-if="value.parameter_type === 'Number'">
                                            <input class="form-control" type="number" style="width:100%" v-model="value.value">
                                        </template>
                                    </td>
                                </tr>
                            </table>
                        </template>
                    </div>
                    Payload Name: <input class="form-control" type="text" size="100" placeholder="Output File Name" id="location" v-model="name"><br>
                    Payload's Default Description: <input class="form-control" type="text" size="100" placeholder="Default Description of associated Callbacks" v-model="tag" id="default_tag">
                </template>
                <template v-else>
                    <h2>No Payload Types match those C2 profiles, OS, and Architecture</h2>
                </template>
            </div>
            <div :hidden="!pt_buttons" class="card-footer bg-card-footer border shadow border-dark">
                <button class="btn btn{{config['outline-buttons']}}warning" id="move_from_payloads_button" @click="move_from_payloads()">Back</button>
                <button class="btn btn{{config['outline-buttons']}}success" id="move_to_commands_button" @click="move_to_commands()">Next</button>
            </div>
        </div>
    </div>
    <div class="card">
        <div class="card-header bg-header border border-dark shadow text-white">
            <h3>Select <span class="operator">Commands</span></h3>
        </div>
        <div class="collapse" id="commands-card-body">
            <div class="card-body border shadow border-dark bg-card-body">
                [[command_message]]<br>
                <select style="width:auto;overflow:auto" class="form-control" multiple id="payload_commands" size="30" v-model="selected_payload_commands">
                    <option v-for="c in payload_command_options" v-model="c" :value="c" :disabled="disable_commands">[[c.cmd]]</option>
                </select>
            </div>
            <div class="card-footer bg-card-footer border shadow border-dark">
                <button class="btn btn{{config['outline-buttons']}}warning" id="move_from_commands_button" @click="move_from_commands()">Back</button>
                <button :hidden="create_buttons" class="btn btn{{config['outline-buttons']}}success" id="move_to_submit_button" @click="submit_payload()">Create</button>
            </div>
        </div>
    </div>
    <!-- THIS IS OUR MODAL FOR UPLOADING FILES -->
<div class="modal fade" id="uploadConfigModal" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header bg-dark text-white">
                <h3 >Generate New Payload Based on Uploaded Config</h3>
                <button type="button" class="close" data-dismiss="modal">×</button>
            </div>
              <div class="modal-body">
                  Generate a new payload based on a config that was exported from the Payloads page.<br/>
                  Setting randomize to false will make an exact copy, setting it to true will randomize the C2 Profile parameters that are declared as randomizable.<br/><br/>
                  <input class="form-control-file" type="file" id="upload_file"><br>
                  Randomize Values: &nbsp;&nbsp;<span class="material-switch pull-right"><input class="form-control" type="checkbox" v-model="upload_randomize" id="upload_randomize_bool">
                                <label for="upload_randomize_bool" class="btn-info"></label></span>
              </div>
              <div class="modal-footer">
                <button class="btn btn{{config['outline-buttons']}}secondary" data-dismiss="modal" aria-hidden="true">Cancel</button>
                <button class="btn btn{{config['outline-buttons']}}primary" data-dismiss="modal" id="uploadConfigModalSubmit">Submit</button>
              </div>
        </div>
    </div>
</div>
<!-- END MODAL FOR UPLOADING FILES -->
</div>

{% endblock %}

{% block scripts %}
{% include "payloads_creation.js" %}
{% endblock %}

{% block body_config %}
.datepicker {
    background-color: white;
}
{% endblock %}